<template>
	<view class="container">
		<view class="userinfo">
			<image :src="userinfo.headicon"></image>
			<text>{{userinfo.username}}</text>
		</view>
		<view class="options">
			<view class="item">
				<image :src="itemicon[0].icon" mode="heightFix"></image>
				个人信息
			</view>
			<view class="item">
				<image :src="itemicon[1].icon" mode="heightFix"></image>
				订单列表
			</view>
			<view class="item">
				<image :src="itemicon[2].icon" mode="heightFix"></image>
				修改密码
			</view>
			<view class="item">
				<image :src="itemicon[3].icon" mode="heightFix"></image>
				意见反馈
			</view>
		</view>
		<button type="primary" size="default" @click="handleLoginLogout">{{isLogin?'退出登录':'点击登录'}}</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isLogin: false,
				userinfo: {
					headicon: '/static/head_icon.png',
					username: ''
				},
				itemicon: [{
						icon: '/static/个人信息.png'
					},
					{
						icon: '/static/订单列表.png'
					},
					{
						icon: '/static/修改密码.png'
					},
					{
						icon: '/static/意见反馈.png'
					}
				]
			}
		},
		methods: {
			handleLoginLogout() {
				if (this.isLogin) {
					uni.showModal({
						title: '确认退出',
						content: '您确定要退出登录吗？',
						success: (res) => {
							if (res.confirm) {
								this.isLogin = false;
								this.userinfo.username = '未登录'
								uni.removeStorageSync('userInfo');
							}
						}
					});
				} else {
					uni.navigateTo({
						url: "/pages/login/login"
					});
				}
			}
		},
		onShow() {
			let userInfo = uni.getStorageSync('userInfo')
			if (userInfo) {
				this.userinfo.username = userInfo.name
				this.isLogin = true
			} else {
				this.userinfo.username = '未登录'
				this.isLogin = false
			}
		}
	}
</script>

<style>
	.container {
		width: 100%;
		height: 100%;
	}

	.userinfo {
		display: flex;
		flex-direction: row;
		align-items: center;
		margin: 0 0 15% 15%;
		padding-top: 15%;
	}

	.userinfo image {
		width: 60px;
		height: 60px;
		border-radius: 50%;
	}

	.userinfo text {
		color: #777;
		margin-left: 10%;
	}

	.options {
		width: 94%;
		margin-left: 3%;
	}

	.item {
		display: flex;
		flex-direction: row;
		align-items: center;
		border-bottom: 1px #D0D0D0 solid;
		padding-top: 8px;
		padding-bottom: 8px;
		position: relative;
	}

	.item:first-child {
		border-top: 1px #D0D0D0 solid;
	}

	.item::after {
		content: '';
		width: 18px;
		height: 18px;
		background-image: url('../../static/more.png');
		background-repeat: no-repeat;
		background-position: center right;
		background-size: 18px 18px;
		position: absolute;
		right: 0;
	}

	.item image {
		height: 18px;
		height: 18px;
		margin-right: 10px;
	}

	button {
		margin-top: 10%;
		width: 94%;
	}
</style>